﻿using System.Collections.Generic;
using HCQ2_IBLL;
using HCQ2_Model.APPModel.ResultApiModel;
using HCQ2_Model.APPModel.ParamModel;
using System.Web;

namespace HCQ2_BLL
{
    public partial class T_ClassBLL: IT_ClassBLL
    {
        //******************************************接口*******************************************
        /// <summary>
        ///  获取班级列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<ClassListResult> GetClassList(ClassListModel model,int userId)
        {
            return DBSession.IT_ClassDAL.GetClassList(model,userId);
        }
        /// <summary>
        ///  获取关注班级列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<ClassListResult> GetFocusClassList(ClassListModel model, int userId)
        {
            int mark = DBSession.IT_VRFocusClassDAL.SelectCount(s => s.user_id == userId && s.mark);
            return DBSession.IT_ClassDAL.GetFocusClassList(model, userId, mark);
        }
        /// <summary>
        ///  获取体验时长排行榜
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<ExperienceRankList> GetExperienceRankList(ExperienceRankParam param, int userId)
        {
            return DBSession.IT_ClassDAL.GetExperienceRankList(param, userId);
        }
        /// <summary>
        ///  获取体验正确率
        /// </summary>
        /// <param name="param"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List<CorrectRateResult> GetCorrectRateList(ExperienceRankParam param, int userId)
        {
            return DBSession.IT_ClassDAL.GetCorrectRateList(param, userId);
        }
        /// <summary>
        ///  获取单词出错次数统计
        /// </summary>
        /// <param name="param"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List<WordErrorModel> GetWordErrorNumList(ExperienceRankParam param, int userId)
        {
            return DBSession.IT_ClassDAL.GetWordErrorNumList(param, userId);
        }
        /// <summary>
        ///  获取用户登录信息
        /// </summary>
        /// <param name="param"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List<UserInfoByLoginModel> GetUserLoginInfo(ExperienceRankParam param, int userId)
        {
            return DBSession.IT_ClassDAL.GetUserLoginInfo(param, userId);
        }
        /// <summary>
        ///  获取学生列表
        /// </summary>
        /// <param name="param"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List<StudentInfoResult> GetStudentInfoList(StudentLoginModel param, int userId)
        {
            var query = DBSession.IT_ClassDAL.GetStudentInfoList(param, userId);//accuracy
            query.ForEach(o =>
            {
                if (!string.IsNullOrEmpty(o.user_img) && o.user_img.IndexOf("http")<0)
                    o.user_img = HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")) + o.user_img.Replace("~", "");
                if (o.result_error == 0)
                {
                    if (!string.IsNullOrEmpty(o.file_name))
                        o.accuracy = 100;
                }
                else
                {
                    float total = (float)(o.result_ok + o.result_error);
                    o.accuracy = (float.Parse(((float)o.result_ok / total).ToString("F2"))) * 100;                    
                }
            });
            return query;
        }
        /// <summary>
        ///  获取在线体验用户数量
        /// </summary>
        /// <param name="param"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public int GetOnLineNum(StudentLoginModel param, int userId)
        {
            return DBSession.IT_ClassDAL.GetOnLineNum(param, userId);
        }
    }
}
